﻿Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.ComponentModel.Design.Serialization
Imports System.Diagnostics
Imports System.Drawing
Imports System.Drawing.Design
Imports System.Globalization
Imports System.IO
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.Text
Imports System.Workflow.ComponentModel.Compiler
Imports System.Workflow.ComponentModel.Design
Imports System.Workflow.ComponentModel.Serialization
Imports System.Workflow.Runtime

Namespace System.Workflow.ComponentModel
    <ActivityValidator(GetType(ActivityValidator)), RuntimeNameProperty("Name"), ToolboxItemFilter("System.Workflow.ComponentModel.Design.ActivitySet", ToolboxItemFilterType.Allow), DesignerSerializer(GetType(ActivityMarkupSerializer), GetType(WorkflowMarkupSerializer)), Designer(GetType(ActivityDesigner), GetType(IRootDesigner)), ToolboxItem(GetType(ActivityToolboxItem)), ToolboxBitmap(GetType(Activity), "Design.Resources.Activity.png"), ToolboxItemFilter("Microsoft.Workflow.VSDesigner", ToolboxItemFilterType.Require), ActivityCodeGenerator(GetType(ActivityCodeGenerator)), DesignerSerializer(GetType(ActivityCodeDomSerializer), GetType(CodeDomSerializer)), DesignerSerializer(GetType(ActivityTypeCodeDomSerializer), GetType(TypeCodeDomSerializer)), DesignerCategory("Component"), ActivityExecutor(GetType(ActivityExecutor([Of] Activity))), Designer(GetType(ActivityDesigner), GetType(IDesigner))> _
    Public Class Activity
        Inherits DependencyObject
        ' Events
        Friend Shared Custom Event ActivityResolve As ActivityResolveEventHandler
            AddHandler(ByVal value As ActivityResolveEventHandler)
                SyncLock Activity.staticSyncRoot
                    Activity.activityDefinitionResolve = DirectCast(Delegate.Combine(Activity.activityDefinitionResolve, value), ActivityResolveEventHandler)
                End SyncLock
            End AddHandler
            RemoveHandler(ByVal value As ActivityResolveEventHandler)
                SyncLock Activity.staticSyncRoot
                    Activity.activityDefinitionResolve = DirectCast(Delegate.Remove(Activity.activityDefinitionResolve, value), ActivityResolveEventHandler)
                End SyncLock
            End RemoveHandler
        End Event
        <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(False)> _
        Public Custom Event Canceling As EventHandler([Of] ActivityExecutionStatusChangedEventArgs)
            AddHandler(ByVal value As EventHandler([Of] ActivityExecutionStatusChangedEventArgs))
                Me.AddStatusChangeHandler(Activity.CancelingEvent, value)
            End AddHandler
            RemoveHandler(ByVal value As EventHandler([Of] ActivityExecutionStatusChangedEventArgs))
                Me.RemoveStatusChangeHandler(Activity.CancelingEvent, value)
            End RemoveHandler
        End Event
        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Public Custom Event Closed As EventHandler([Of] ActivityExecutionStatusChangedEventArgs)
            AddHandler(ByVal value As EventHandler([Of] ActivityExecutionStatusChangedEventArgs))
                Me.AddStatusChangeHandler(Activity.ClosedEvent, value)
            End AddHandler
            RemoveHandler(ByVal value As EventHandler([Of] ActivityExecutionStatusChangedEventArgs))
                Me.RemoveStatusChangeHandler(Activity.ClosedEvent, value)
            End RemoveHandler
        End Event
        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Public Custom Event Compensating As EventHandler([Of] ActivityExecutionStatusChangedEventArgs)
            AddHandler(ByVal value As EventHandler([Of] ActivityExecutionStatusChangedEventArgs))
                Me.AddStatusChangeHandler(Activity.CompensatingEvent, value)
            End AddHandler
            RemoveHandler(ByVal value As EventHandler([Of] ActivityExecutionStatusChangedEventArgs))
                Me.RemoveStatusChangeHandler(Activity.CompensatingEvent, value)
            End RemoveHandler
        End Event
        <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(False)> _
        Public Custom Event Executing As EventHandler([Of] ActivityExecutionStatusChangedEventArgs)
            AddHandler(ByVal value As EventHandler([Of] ActivityExecutionStatusChangedEventArgs))
                Me.AddStatusChangeHandler(Activity.ExecutingEvent, value)
            End AddHandler
            RemoveHandler(ByVal value As EventHandler([Of] ActivityExecutionStatusChangedEventArgs))
                Me.RemoveStatusChangeHandler(Activity.ExecutingEvent, value)
            End RemoveHandler
        End Event
        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Public Custom Event Faulting As EventHandler([Of] ActivityExecutionStatusChangedEventArgs)
            AddHandler(ByVal value As EventHandler([Of] ActivityExecutionStatusChangedEventArgs))
                Me.AddStatusChangeHandler(Activity.FaultingEvent, value)
            End AddHandler
            RemoveHandler(ByVal value As EventHandler([Of] ActivityExecutionStatusChangedEventArgs))
                Me.RemoveStatusChangeHandler(Activity.FaultingEvent, value)
            End RemoveHandler
        End Event
        <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(False)> _
        Public Custom Event StatusChanged As EventHandler([Of] ActivityExecutionStatusChangedEventArgs)
            AddHandler(ByVal value As EventHandler([Of] ActivityExecutionStatusChangedEventArgs))
                Me.AddStatusChangeHandler(Activity.StatusChangedEvent, value)
            End AddHandler
            RemoveHandler(ByVal value As EventHandler([Of] ActivityExecutionStatusChangedEventArgs))
                Me.RemoveStatusChangeHandler(Activity.StatusChangedEvent, value)
            End RemoveHandler
        End Event
        Friend Shared Custom Event WorkflowChangeActionsResolve As WorkflowChangeActionsResolveEventHandler
            AddHandler(ByVal value As WorkflowChangeActionsResolveEventHandler)
                SyncLock Activity.staticSyncRoot
                    Activity.workflowChangeActionsResolve = DirectCast(Delegate.Combine(Activity.workflowChangeActionsResolve, value), WorkflowChangeActionsResolveEventHandler)
                End SyncLock
            End AddHandler
            RemoveHandler(ByVal value As WorkflowChangeActionsResolveEventHandler)
                SyncLock Activity.staticSyncRoot
                    Activity.workflowChangeActionsResolve = DirectCast(Delegate.Remove(Activity.workflowChangeActionsResolve, value), WorkflowChangeActionsResolveEventHandler)
                End SyncLock
            End RemoveHandler
        End Event

        ' Methods
        Shared Sub New()
            Activity.binaryFormatter = New BinaryFormatter
            Activity.binaryFormatter.SurrogateSelector = ActivitySurrogateSelector.Default
            DependencyProperty.RegisterAsKnown(Activity.ActivityExecutionContextInfoProperty, 1, PropertyValidity.Reexecute)
            DependencyProperty.RegisterAsKnown(Activity.CompletedExecutionContextsProperty, 2, PropertyValidity.Reexecute)
            DependencyProperty.RegisterAsKnown(Activity.ActiveExecutionContextsProperty, 3, PropertyValidity.Uninitialize)
            DependencyProperty.RegisterAsKnown(Activity.CompletedOrderIdProperty, 4, PropertyValidity.Uninitialize)
            DependencyProperty.RegisterAsKnown(Activity.ExecutionStatusProperty, 5, PropertyValidity.Reexecute)
            DependencyProperty.RegisterAsKnown(Activity.ExecutionResultProperty, 6, PropertyValidity.Reexecute)
            DependencyProperty.RegisterAsKnown(Activity.WasExecutingProperty, 7, PropertyValidity.Uninitialize)
            DependencyProperty.RegisterAsKnown(Activity.LockCountOnStatusChangeProperty, 8, PropertyValidity.Uninitialize)
            DependencyProperty.RegisterAsKnown(Activity.HasPrimaryClosedProperty, 9, PropertyValidity.Uninitialize)
            DependencyProperty.RegisterAsKnown(Activity.NestedActivitiesProperty, 10, PropertyValidity.Uninitialize)
            DependencyProperty.RegisterAsKnown(Activity.ActivityContextGuidProperty, 11, PropertyValidity.Reexecute)
            DependencyProperty.RegisterAsKnown(Activity.WorkflowXamlMarkupProperty, 12, PropertyValidity.Uninitialize)
            DependencyProperty.RegisterAsKnown(Activity.WorkflowRulesMarkupProperty, 13, PropertyValidity.Uninitialize)
            DependencyProperty.RegisterAsKnown(ActivityExecutionContext.CurrentExceptionProperty, &H17, PropertyValidity.Reexecute)
            DependencyProperty.RegisterAsKnown(ActivityExecutionContext.GrantedLocksProperty, &H18, PropertyValidity.Uninitialize)
            DependencyProperty.RegisterAsKnown(ActivityExecutionContext.LockAcquiredCallbackProperty, &H19, PropertyValidity.Uninitialize)
            DependencyProperty.RegisterAsKnown(Activity.ExecutingEvent, &H1F, PropertyValidity.Uninitialize)
            DependencyProperty.RegisterAsKnown(Activity.CancelingEvent, &H20, PropertyValidity.Uninitialize)
            DependencyProperty.RegisterAsKnown(Activity.ClosedEvent, &H21, PropertyValidity.Uninitialize)
            DependencyProperty.RegisterAsKnown(Activity.CompensatingEvent, &H22, PropertyValidity.Uninitialize)
            DependencyProperty.RegisterAsKnown(Activity.StatusChangedEvent, &H23, PropertyValidity.Uninitialize)
            DependencyProperty.RegisterAsKnown(Activity.StatusChangedLockedEvent, &H24, PropertyValidity.Uninitialize)
            DependencyProperty.RegisterAsKnown(Activity.LockCountOnStatusChangeChangedEvent, &H25, PropertyValidity.Uninitialize)
            DependencyProperty.RegisterAsKnown(Activity.FaultingEvent, &H26, PropertyValidity.Uninitialize)
            DependencyProperty.RegisterAsKnown(FaultAndCancellationHandlingFilter.FaultProcessedProperty, &H29, PropertyValidity.Uninitialize)
            DependencyProperty.RegisterAsKnown(CompensationHandlingFilter.CompensateProcessedProperty, &H2B, PropertyValidity.Uninitialize)
            DependencyProperty.RegisterAsKnown(CompensationHandlingFilter.LastCompensatedOrderIdProperty, &H2C, PropertyValidity.Uninitialize)
        End Sub

        Public Sub New()
            MyBase.SetValue(Activity.CustomActivityProperty, False)
            MyBase.SetValue(Activity.NameProperty, MyBase.GetType.Name)
        End Sub

        Public Sub New(ByVal name As String)
            If (name Is Nothing) Then
                Throw New ArgumentNullException("name")
            End If
            MyBase.SetValue(Activity.CustomActivityProperty, False)
            MyBase.SetValue(Activity.NameProperty, name)
        End Sub

        Friend Shared Function ActivityExecutionResultEnumToString(ByVal activityExecutionResult As ActivityExecutionResult) As String
            Dim str As String = String.Empty
            Select Case activityExecutionResult
                Case ActivityExecutionResult.None
                    Return "None"
                Case ActivityExecutionResult.Succeeded
                    Return "Succeeded"
                Case ActivityExecutionResult.Canceled
                    Return "Canceled"
                Case ActivityExecutionResult.Compensated
                    Return "Compensated"
                Case ActivityExecutionResult.Faulted
                    Return "Faulted"
            End Select
            Return str
        End Function

        Friend Shared Function ActivityExecutionStatusEnumToString(ByVal status As ActivityExecutionStatus) As String
            Dim str As String = String.Empty
            Select Case status
                Case ActivityExecutionStatus.Initialized
                    Return "Initialized"
                Case ActivityExecutionStatus.Executing
                    Return "Executing"
                Case ActivityExecutionStatus.Canceling
                    Return "Canceling"
                Case ActivityExecutionStatus.Closed
                    Return "Closed"
                Case ActivityExecutionStatus.Compensating
                    Return "Compensating"
                Case ActivityExecutionStatus.Faulting
                    Return "Faulting"
            End Select
            Return str
        End Function

        Private Sub AddStatusChangeHandler(ByVal dependencyProp As DependencyProperty, ByVal delegateValue As EventHandler([Of] ActivityExecutionStatusChangedEventArgs))
            Dim list As IList = Nothing
            If MyBase.DependencyPropertyValues.ContainsKey(dependencyProp) Then
                list = [TryCast](MyBase.DependencyPropertyValues.Item(dependencyProp),IList)
            Else
                list = New ArrayList
                MyBase.DependencyPropertyValues.Item(dependencyProp) = list
            End If
            list.Add(New ActivityExecutorDelegateInfo([Of] ActivityExecutionStatusChangedEventArgs)(True, delegateValue, If(Me.ContextActivity <>  Nothing , Me.ContextActivity, Me.RootActivity)))
        End Sub

        Protected Friend Overridable Function Cancel(ByVal executionContext As ActivityExecutionContext) As ActivityExecutionStatus
            If (executionContext Is Nothing) Then
                Throw New ArgumentNullException("executionContext")
            End If
            Return ActivityExecutionStatus.Closed
        End Function

        Public Function Clone() As Activity
            If MyBase.DesignMode Then
                Throw New InvalidOperationException(SR.GetString("Error_NoRuntimeAvailable"))
            End If
            Dim num As Long = CLng(MyBase.GetValue(Activity.SerializedStreamLengthProperty))
            If (num = 0) Then
                num = &H2800
            End If
            Dim stream As New MemoryStream(CInt(num))
            Me.Save(stream)
            stream.Position = 0
            MyBase.SetValue(Activity.SerializedStreamLengthProperty, If((stream.Length > num), stream.Length, num))
            Return Activity.Load(stream, Me)
        End Function

        Friend Overridable Function CollectNestedActivities() As IList([Of] Activity)
            Return Nothing
        End Function

        Friend Sub DecrementCompletedOrderId()
            Dim num As Integer = CInt(Me.RootActivity.GetValue(Activity.CompletedOrderIdProperty))
            Me.RootActivity.SetValue(Activity.CompletedOrderIdProperty, (num - 1))
        End Sub

        Protected Friend Overridable Function Execute(ByVal executionContext As ActivityExecutionContext) As ActivityExecutionStatus
            If (executionContext Is Nothing) Then
                Throw New ArgumentNullException("executionContext")
            End If
            Return ActivityExecutionStatus.Closed
        End Function

        Private Shared Sub FillContextIdToActivityMap(ByVal seedActivity As Activity)
            Dim queue As New Queue([Of] Activity)
            queue.Enqueue(seedActivity)
            Do While (queue.Count > 0)
                Dim activity As Activity = queue.Dequeue
                If activity.IsContextActivity Then
                    Activity.ContextIdToActivityMap.Item(activity.ContextId) = activity
                    Dim list As IList([Of] Activity) = DirectCast(activity.GetValue(Activity.ActiveExecutionContextsProperty), IList([Of] Activity))
                    If (Not list Is Nothing) Then
                        Dim activity2 As Activity
                        For Each activity2 In list
                            queue.Enqueue(activity2)
                        Next
                    End If
                Else
                    Activity.ContextIdToActivityMap.Item(0) = activity
                End If
            Loop
            Activity.ActivityRoots = New ArrayList(Activity.ContextIdToActivityMap.Values)
        End Sub

        Private Sub FireStatusChangedEvents(ByVal dependencyProperty As DependencyProperty, ByVal transacted As Boolean)
            Dim statusChangeHandlers As IList = Me.GetStatusChangeHandlers(dependencyProperty)
            If (Not statusChangeHandlers Is Nothing) Then
                Dim e As New ActivityExecutionStatusChangedEventArgs(Me.ExecutionStatus, Me.ExecutionResult, Me)
                Dim info As ActivityExecutorDelegateInfo([Of] ActivityExecutionStatusChangedEventArgs)
                For Each info In statusChangeHandlers
                    info.InvokeDelegate(Me.ContextActivity, e, (info.ActivityQualifiedName Is Nothing), transacted)
                Next
            End If
        End Sub

        Friend Overrides Sub FixUpMetaProperties(ByVal originalObject As DependencyObject)
            If (originalObject Is Nothing) Then
                Throw New ArgumentNullException
            End If
            MyBase.FixUpMetaProperties(originalObject)
        End Sub

        Friend Overridable Sub FixUpParentChildRelationship(ByVal definitionActivity As Activity, ByVal parentActivity As Activity, ByVal deserializedActivities As Hashtable)
            If (Not parentActivity Is Nothing) Then
                Me.SetParent(DirectCast(parentActivity, CompositeActivity))
            End If
        End Sub

        Public Function GetActivityByName(ByVal activityQualifiedName As String) As Activity
            Return Me.GetActivityByName(activityQualifiedName, False)
        End Function

        Public Function GetActivityByName(ByVal activityQualifiedName As String, ByVal withinThisActivityOnly As Boolean) As Activity
            If (activityQualifiedName Is Nothing) Then
                Throw New ArgumentNullException("activityQualifiedName")
            End If
            If (Me.QualifiedName = activityQualifiedName) Then
                Return Me
            End If
            Dim activity As Activity = Nothing
            activity = Me.ResolveActivityByName(activityQualifiedName, withinThisActivityOnly)
            If (((activity Is Nothing) AndAlso TypeOf Me Is CompositeActivity) AndAlso Helpers.IsCustomActivity([TryCast](Me,CompositeActivity))) Then
                activity = Me.ResolveActivityByName((Me.QualifiedName & "." & activityQualifiedName), withinThisActivityOnly)
            End If
            Return activity
        End Function

        Private Function GetStatusChangeHandlers(ByVal dependencyProp As DependencyProperty) As IList
            Dim list As IList = Nothing
            If MyBase.DependencyPropertyValues.ContainsKey(dependencyProp) Then
                list = [TryCast](MyBase.DependencyPropertyValues.Item(dependencyProp),IList)
            End If
            Return list
        End Function

        Protected Friend Overridable Function HandleFault(ByVal executionContext As ActivityExecutionContext, ByVal exception As Exception) As ActivityExecutionStatus
            If (executionContext Is Nothing) Then
                Throw New ArgumentNullException("executionContext")
            End If
            Return ActivityExecutionStatus.Closed
        End Function

        Friend Sub HoldLockOnStatusChange(ByVal eventListener As IActivityEventListener([Of] ActivityExecutionStatusChangedEventArgs))
            Me.RegisterForStatusChange(Activity.StatusChangedLockedEvent, eventListener)
            MyBase.SetValue(Activity.LockCountOnStatusChangeProperty, (Me.LockCountOnStatusChange + 1))
        End Sub

        Friend Function IncrementCompletedOrderId() As Integer
            Dim num As Integer = CInt(Me.RootActivity.GetValue(Activity.CompletedOrderIdProperty))
            Me.RootActivity.SetValue(Activity.CompletedOrderIdProperty, (num + 1))
            Return (num + 1)
        End Function

        Protected Friend Overridable Sub Initialize(ByVal provider As IServiceProvider)
            If (provider Is Nothing) Then
                Throw New ArgumentNullException("provider")
            End If
        End Sub

        Protected Friend Sub Invoke([Of] T As EventArgs)(ByVal handler As EventHandler([Of] T), ByVal e As T)
            If (handler Is Nothing) Then
                Throw New ArgumentNullException("handler")
            End If
            If (e Is Nothing) Then
                Throw New ArgumentNullException("e")
            End If
            If (Me.WorkflowCoreRuntime Is Nothing) Then
                Throw New InvalidOperationException(SR.GetString(CultureInfo.CurrentCulture, "Error_NoRuntimeAvailable"))
            End If
            If ((Me.ExecutionStatus = ActivityExecutionStatus.Initialized) OrElse (Me.ExecutionStatus = ActivityExecutionStatus.Closed)) Then
                Throw New InvalidOperationException(SR.GetString(CultureInfo.CurrentCulture, "Error_InvalidInvokingState"))
            End If
            Dim info As ActivityExecutorDelegateInfo([Of] T) = Nothing
            [Using] Me.WorkflowCoreRuntime.SetCurrentActivity(Me)
                info = New ActivityExecutorDelegateInfo([Of] T)(handler, Me.ContextActivity)
            End [Using]
            info.InvokeDelegate(Me.WorkflowCoreRuntime.CurrentActivity.ContextActivity, e, False)
        End Sub

        Protected Friend Sub Invoke([Of] T As EventArgs)(ByVal eventListener As IActivityEventListener([Of] T), ByVal e As T)
            If (eventListener Is Nothing) Then
                Throw New ArgumentNullException("eventListener")
            End If
            If (e Is Nothing) Then
                Throw New ArgumentNullException("e")
            End If
            If (Me.WorkflowCoreRuntime Is Nothing) Then
                Throw New InvalidOperationException(SR.GetString(CultureInfo.CurrentCulture, "Error_NoRuntimeAvailable"))
            End If
            If ((Me.ExecutionStatus = ActivityExecutionStatus.Initialized) OrElse (Me.ExecutionStatus = ActivityExecutionStatus.Closed)) Then
                Throw New InvalidOperationException(SR.GetString(CultureInfo.CurrentCulture, "Error_InvalidInvokingState"))
            End If
            Dim info As ActivityExecutorDelegateInfo([Of] T) = Nothing
            [Using] Me.WorkflowCoreRuntime.SetCurrentActivity(Me)
                info = New ActivityExecutorDelegateInfo([Of] T)(eventListener, Me.ContextActivity)
            End [Using]
            info.InvokeDelegate(Me.WorkflowCoreRuntime.CurrentActivity.ContextActivity, e, False)
        End Sub

        Public Shared Function Load(ByVal stream As Stream, ByVal outerActivity As Activity) As Activity
            Return Activity.Load(stream, outerActivity, Activity.binaryFormatter)
        End Function

        Public Shared Function Load(ByVal stream As Stream, ByVal outerActivity As Activity, ByVal formatter As IFormatter) As Activity
            If (stream Is Nothing) Then
                Throw New ArgumentNullException("stream")
            End If
            If (formatter Is Nothing) Then
                Throw New ArgumentNullException("formatter")
            End If
            If ((Not outerActivity Is Nothing) AndAlso outerActivity.DesignMode) Then
                Throw New InvalidOperationException(SR.GetString("Error_NoRuntimeAvailable"))
            End If
            Dim item As Activity = Nothing
            Dim contextIdToActivityMap As Hashtable = Activity.ContextIdToActivityMap
            Dim definitionActivity As Activity = Activity.DefinitionActivity
            Activity.ContextIdToActivityMap = New Hashtable
            Activity.DefinitionActivity = outerActivity
            Try 
                If (Not outerActivity Is Nothing) Then
                    Activity.FillContextIdToActivityMap(outerActivity.RootActivity)
                End If
                item = DirectCast(formatter.Deserialize(stream), Activity)
                Dim queue As New Queue([Of] Activity)
                queue.Enqueue(item)
                Do While (queue.Count > 0)
                    Dim activity3 As Activity = queue.Dequeue
                    Dim activityByName As Activity = Activity.DefinitionActivity
                    Dim parentActivity As Activity = If((Not outerActivity Is Nothing), outerActivity.parent, Nothing)
                    If activity3.IsContextActivity Then
                        Dim info As ActivityExecutionContextInfo = DirectCast(activity3.GetValue(Activity.ActivityExecutionContextInfoProperty), ActivityExecutionContextInfo)
                        activityByName = activityByName.GetActivityByName(info.ActivityQualifiedName)
                        Dim activity6 As Activity = DirectCast(Activity.ContextIdToActivityMap.Item(info.ParentContextId), Activity)
                        If (Not activity6 Is Nothing) Then
                            parentActivity = activity6.GetActivityByName(info.ActivityQualifiedName).parent
                        End If
                        Activity.ContextIdToActivityMap.Item(activity3.ContextId) = activity3
                        Dim list As IList([Of] Activity) = DirectCast(activity3.GetValue(Activity.ActiveExecutionContextsProperty), IList([Of] Activity))
                        If (Not list Is Nothing) Then
                            Dim activity7 As Activity
                            For Each activity7 In list
                                queue.Enqueue(activity7)
                            Next
                        End If
                    End If
                    Dim deserializedActivities As New Hashtable
                    Dim list2 As IList([Of] Activity) = DirectCast(activity3.GetValue(Activity.NestedActivitiesProperty), IList([Of] Activity))
                    If (Not list2 Is Nothing) Then
                        Dim activity8 As Activity
                        For Each activity8 In list2
                            deserializedActivities.Add(activity8.DottedPath, activity8)
                        Next
                    End If
                    activity3.FixUpParentChildRelationship(activityByName, parentActivity, deserializedActivities)
                    activity3.FixUpMetaProperties(activityByName)
                    activity3.RemoveProperty(Activity.NestedActivitiesProperty)
                Loop
                If (item.Parent Is Nothing) Then
                    item.SetValue(Activity.WorkflowDefinitionProperty, Activity.DefinitionActivity)
                End If
            Finally
                Activity.ContextIdToActivityMap = contextIdToActivityMap
                Activity.DefinitionActivity = definitionActivity
                Activity.ActivityRoots = Nothing
            End Try
            Return item
        End Function

        Friend Sub MarkCanceled()
            If (Me.ExecutionStatus <> ActivityExecutionStatus.Closed) Then
                If (Me.ExecutionStatus <> ActivityExecutionStatus.Canceling) Then
                    Throw New InvalidOperationException(SR.GetString("Error_InvalidCancelActivityState"))
                End If
                MyBase.SetValue(Activity.ExecutionResultProperty, ActivityExecutionResult.Canceled)
                Me.MarkClosed
            End If
        End Sub

        Private Sub MarkClosed()
            Select Case Me.ExecutionStatus
                Case ActivityExecutionStatus.Executing, ActivityExecutionStatus.Canceling, ActivityExecutionStatus.Compensating, ActivityExecutionStatus.Faulting
                    If TypeOf Me Is CompositeActivity Then
                        Dim activity As Activity
                        For Each activity In DirectCast(Me, CompositeActivity).Activities
                            If ((activity.Enabled AndAlso (activity.ExecutionStatus <> ActivityExecutionStatus.Initialized)) AndAlso (activity.ExecutionStatus <> ActivityExecutionStatus.Closed)) Then
                                Throw New InvalidOperationException(SR.GetString(CultureInfo.CurrentCulture, "Error_ActiveChildExist"))
                            End If
                        Next
                        Dim context As New ActivityExecutionContext(Me)
                        Dim context2 As ActivityExecutionContext
                        For Each context2 In context.ExecutionContextManager.ExecutionContexts
                            If (Not Me.GetActivityByName(context2.Activity.QualifiedName, True) Is Nothing) Then
                                Throw New InvalidOperationException(SR.GetString(CultureInfo.CurrentCulture, "Error_ActiveChildContextExist"))
                            End If
                        Next
                    End If
                    If (Me.LockCountOnStatusChange > 0) Then
                        MyBase.SetValue(Activity.HasPrimaryClosedProperty, True)
                        Me.FireStatusChangedEvents(Activity.StatusChangedLockedEvent, False)
                        Return
                    End If
                    If ((Me.parent Is Nothing) OrElse ((Me.ExecutionResult = ActivityExecutionResult.Succeeded) AndAlso (TypeOf Me Is ICompensatableActivity OrElse Me.PersistOnClose))) Then
                        Dim executionStatus As ActivityExecutionStatus = Me.ExecutionStatus
                        Dim executionResult As ActivityExecutionResult = Me.ExecutionResult
                        Me.SetStatus(ActivityExecutionStatus.Closed, True)
                        Try 
                            Me.OnClosed(Me.RootActivity.WorkflowCoreRuntime)
                        Catch exception As Exception
                            MyBase.SetValue(Activity.ExecutionResultProperty, ActivityExecutionResult.Faulted)
                            MyBase.SetValueCommon(ActivityExecutionContext.CurrentExceptionProperty, exception, ActivityExecutionContext.CurrentExceptionProperty.DefaultMetadata, False)
                        End Try
                        If ((Not Me.parent Is Nothing) AndAlso TypeOf Me Is ICompensatableActivity) Then
                            MyBase.SetValue(Activity.CompletedOrderIdProperty, Me.IncrementCompletedOrderId)
                        End If
                        If Me.CanUninitializeNow Then
                            Me.Uninitialize(Me.RootActivity.WorkflowCoreRuntime)
                            MyBase.SetValue(Activity.ExecutionResultProperty, ActivityExecutionResult.Uninitialized)
                        ElseIf (Me.parent Is Nothing) Then
                            Activity.UninitializeCompletedContext(Me, New ActivityExecutionContext(Me))
                        End If
                        Try 
                            Dim exception2 As Exception = DirectCast(MyBase.GetValue(ActivityExecutionContext.CurrentExceptionProperty), Exception)
                            If ((Not exception2 Is Nothing) AndAlso (Me.parent Is Nothing)) Then
                                Me.WorkflowCoreRuntime.ActivityStatusChanged(Me, False, True)
                                Dim message As String = ("Uncaught exception escaped to the root of the workflow." & ChrW(10) & String.Format(CultureInfo.CurrentCulture, "    In instance {0} in activity {1}" & ChrW(10), New Object() { Me.WorkflowInstanceId, String.Empty }) & String.Format(CultureInfo.CurrentCulture, "Inner exception: {0}", New Object() { exception2 }))
                                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Critical, 0, message)
                                Me.WorkflowCoreRuntime.TerminateInstance(exception2)
                            ElseIf ((Not exception2 Is Nothing) AndAlso (Not Me.parent Is Nothing)) Then
                                Me.WorkflowCoreRuntime.RaiseException(exception2, Me.Parent, String.Empty)
                                MyBase.RemoveProperty(ActivityExecutionContext.CurrentExceptionProperty)
                            ElseIf ((Me.parent Is Nothing) OrElse Me.PersistOnClose) Then
                                Me.WorkflowCoreRuntime.PersistInstanceState(Me)
                                Me.WorkflowCoreRuntime.ActivityStatusChanged(Me, False, True)
                                If (Not exception2 Is Nothing) Then
                                    Me.WorkflowCoreRuntime.RaiseException(exception2, Me.Parent, String.Empty)
                                    MyBase.RemoveProperty(ActivityExecutionContext.CurrentExceptionProperty)
                                End If
                            End If
                            Dim activity2 As Activity = Me.parent
                            Do While (Not activity2 Is Nothing)
                                If (activity2.SupportsSynchronization OrElse (activity2.Parent Is Nothing)) Then
                                    activity2.RemoveProperty(ActivityExecutionContext.CachedGrantedLocksProperty)
                                End If
                                activity2 = activity2.parent
                            Loop
                            Return
                        Catch obj1 As Object
                            If ((Not Me.parent Is Nothing) AndAlso TypeOf Me Is ICompensatableActivity) Then
                                MyBase.RemoveProperty(Activity.CompletedOrderIdProperty)
                                Me.DecrementCompletedOrderId
                            End If
                            MyBase.SetValue(Activity.ExecutionResultProperty, executionResult)
                            Me.SetStatus(executionStatus, True)
                            Dim activity3 As Activity = Me.parent
                            Do While (Not activity3 Is Nothing)
                                If (activity3.SupportsSynchronization OrElse (activity3.Parent Is Nothing)) Then
                                    Dim obj2 As Object = activity3.GetValue(ActivityExecutionContext.CachedGrantedLocksProperty)
                                    If (Not obj2 Is Nothing) Then
                                        activity3.SetValue(ActivityExecutionContext.GrantedLocksProperty, obj2)
                                    End If
                                    activity3.RemoveProperty(ActivityExecutionContext.CachedGrantedLocksProperty)
                                End If
                                activity3 = activity3.parent
                            Loop
                            Throw
                        End Try
                    End If
                    Me.SetStatus(ActivityExecutionStatus.Closed, False)
                    Try 
                        Me.OnClosed(Me.RootActivity.WorkflowCoreRuntime)
                    Catch exception3 As Exception
                        MyBase.SetValue(Activity.ExecutionResultProperty, ActivityExecutionResult.Faulted)
                        MyBase.SetValueCommon(ActivityExecutionContext.CurrentExceptionProperty, exception3, ActivityExecutionContext.CurrentExceptionProperty.DefaultMetadata, False)
                    End Try
                    If Me.CanUninitializeNow Then
                        Me.Uninitialize(Me.RootActivity.WorkflowCoreRuntime)
                        MyBase.SetValue(Activity.ExecutionResultProperty, ActivityExecutionResult.Uninitialized)
                    End If
                    Dim e As Exception = DirectCast(MyBase.GetValue(ActivityExecutionContext.CurrentExceptionProperty), Exception)
                    If (Not e Is Nothing) Then
                        Me.WorkflowCoreRuntime.RaiseException(e, Me.Parent, String.Empty)
                        MyBase.RemoveProperty(ActivityExecutionContext.CurrentExceptionProperty)
                    End If
                    Return
            End Select
            Throw New InvalidOperationException(SR.GetString("Error_InvalidCloseActivityState"))
        End Sub

        Friend Sub MarkCompensated()
            If (Me.ExecutionStatus <> ActivityExecutionStatus.Compensating) Then
                Throw New InvalidOperationException(SR.GetString("Error_InvalidCompensateActivityState"))
            End If
            MyBase.SetValue(Activity.ExecutionResultProperty, ActivityExecutionResult.Compensated)
            Me.MarkClosed
        End Sub

        Friend Sub MarkCompleted()
            MyBase.SetValue(Activity.ExecutionResultProperty, ActivityExecutionResult.Succeeded)
            Me.MarkClosed
        End Sub

        Friend Sub MarkFaulted()
            MyBase.SetValue(Activity.ExecutionResultProperty, ActivityExecutionResult.Faulted)
            Me.MarkClosed
        End Sub

        Protected Friend Overridable Sub OnActivityExecutionContextLoad(ByVal provider As IServiceProvider)
            If (provider Is Nothing) Then
                Throw New ArgumentNullException("provider")
            End If
        End Sub

        Protected Friend Overridable Sub OnActivityExecutionContextUnload(ByVal provider As IServiceProvider)
            If (provider Is Nothing) Then
                Throw New ArgumentNullException("provider")
            End If
        End Sub

        Protected Overridable Sub OnClosed(ByVal provider As IServiceProvider)
        End Sub

        Friend Overrides Sub OnInitializeActivatingInstanceForRuntime(ByVal workflowCoreRuntime As IWorkflowCoreRuntime)
            MyBase.OnInitializeActivatingInstanceForRuntime(workflowCoreRuntime)
            Me.workflowCoreRuntime = workflowCoreRuntime
        End Sub

        Friend Overrides Sub OnInitializeDefinitionForRuntime()
            If MyBase.DesignMode Then
                MyBase.OnInitializeDefinitionForRuntime
                MyBase.UserData.Item(UserDataKeys.CustomActivity) = MyBase.GetValue(Activity.CustomActivityProperty)
                Dim collection As ICollection([Of] String) = DirectCast(MyBase.GetValue(Activity.SynchronizationHandlesProperty), ICollection([Of] String))
                If Me.SupportsTransaction Then
                    If (collection Is Nothing) Then
                        collection = New List([Of] String)
                    End If
                    collection.Add(TransactionScopeActivity.TransactionScopeActivityIsolationHandle)
                End If
                If (Not collection Is Nothing) Then
                    MyBase.SetValue(Activity.SynchronizationHandlesProperty, New ReadOnlyCollection([Of] String)(New List([Of] String)(collection)))
                End If
                If (Me.Parent Is Nothing) Then
                    Dim hashtable As New Hashtable
                    MyBase.UserData.Item(UserDataKeys.LookupPaths) = hashtable
                    hashtable.Add(Me.QualifiedName, String.Empty)
                End If
                MyBase.SetReadOnlyPropertyValue(Activity.QualifiedNameProperty, Me.QualifiedName)
                MyBase.SetReadOnlyPropertyValue(Activity.DottedPathProperty, Me.DottedPath)
                MyBase.UserData.Item(GetType(PersistOnCloseAttribute)) = (MyBase.GetType.GetCustomAttributes(GetType(PersistOnCloseAttribute), True).Length > 0)
            End If
        End Sub

        Friend Overrides Sub OnInitializeInstanceForRuntime(ByVal workflowCoreRuntime As IWorkflowCoreRuntime)
            MyBase.OnInitializeInstanceForRuntime(workflowCoreRuntime)
            Me.workflowCoreRuntime = workflowCoreRuntime
        End Sub

        Friend Shared Function OnResolveActivityDefinition(ByVal type As Type, ByVal workflowMarkup As String, ByVal rulesMarkup As String, ByVal createNew As Boolean, ByVal initForRuntime As Boolean, ByVal serviceProvider As IServiceProvider) As Activity
            Dim invocationList As Delegate() = Nothing
            SyncLock Activity.staticSyncRoot
                If (Not Activity.activityDefinitionResolve Is Nothing) Then
                    invocationList = Activity.activityDefinitionResolve.GetInvocationList
                End If
            End SyncLock
            Dim activity As Activity = Nothing
            If (Not invocationList Is Nothing) Then
                Dim handler As ActivityResolveEventHandler
                For Each handler In invocationList
                    activity = handler.Invoke(Nothing, New ActivityResolveEventArgs(type, workflowMarkup, rulesMarkup, createNew, initForRuntime, serviceProvider))
                    If (Not activity Is Nothing) Then
                        Return activity
                    End If
                Next
            End If
            Return Nothing
        End Function

        Friend Shared Function OnResolveWorkflowChangeActions(ByVal workflowChangesMarkup As String, ByVal root As Activity) As ArrayList
            Dim invocationList As Delegate() = Nothing
            SyncLock Activity.staticSyncRoot
                If (Not Activity.workflowChangeActionsResolve Is Nothing) Then
                    invocationList = Activity.workflowChangeActionsResolve.GetInvocationList
                End If
            End SyncLock
            Dim list As ArrayList = Nothing
            If (Not invocationList Is Nothing) Then
                Dim handler As WorkflowChangeActionsResolveEventHandler
                For Each handler In invocationList
                    list = handler.Invoke(root, New WorkflowChangeActionsResolveEventArgs(workflowChangesMarkup))
                    If (Not list Is Nothing) Then
                        Return list
                    End If
                Next
            End If
            Return Nothing
        End Function

        Protected Friend Sub [RaiseEvent](ByVal dependencyEvent As DependencyProperty, ByVal sender As Object, ByVal e As EventArgs)
            If (sender Is Nothing) Then
                Throw New ArgumentNullException("sender")
            End If
            If (dependencyEvent Is Nothing) Then
                Throw New ArgumentNullException("dependencyEvent")
            End If
            If (e Is Nothing) Then
                Throw New ArgumentNullException("e")
            End If
            If (Me.WorkflowCoreRuntime Is Nothing) Then
                Throw New InvalidOperationException(SR.GetString("Error_NoRuntimeAvailable"))
            End If
            Dim invocationList As EventHandler() = Me.GetInvocationList([Of] EventHandler)(dependencyEvent)
            If (Not invocationList Is Nothing) Then
                Dim handler As EventHandler
                For Each handler In invocationList
                    Me.WorkflowCoreRuntime.RaiseHandlerInvoking(handler)
                    Try 
                        handler.Invoke(sender, e)
                    Finally
                        Me.WorkflowCoreRuntime.RaiseHandlerInvoked
                    End Try
                Next
            End If
        End Sub

        Protected Friend Sub RaiseGenericEvent([Of] T As EventArgs)(ByVal dependencyEvent As DependencyProperty, ByVal sender As Object, ByVal e As T)
            If (dependencyEvent Is Nothing) Then
                Throw New ArgumentNullException("dependencyEvent")
            End If
            If (e Is Nothing) Then
                Throw New ArgumentNullException("e")
            End If
            If (Me.WorkflowCoreRuntime Is Nothing) Then
                Throw New InvalidOperationException(SR.GetString("Error_NoRuntimeAvailable"))
            End If
            Dim invocationList As EventHandler([Of] T)() = Me.GetInvocationList([Of] EventHandler([Of] T))(dependencyEvent)
            If (Not invocationList Is Nothing) Then
                Dim handler As EventHandler([Of] T)
                For Each handler In invocationList
                    Me.WorkflowCoreRuntime.RaiseHandlerInvoking(handler)
                    Try 
                        handler.Invoke(sender, e)
                    Finally
                        Me.WorkflowCoreRuntime.RaiseHandlerInvoked
                    End Try
                Next
            End If
        End Sub

        Public Sub RegisterForStatusChange(ByVal dependencyProp As DependencyProperty, ByVal activityStatusChangeListener As IActivityEventListener([Of] ActivityExecutionStatusChangedEventArgs))
            If (dependencyProp Is Nothing) Then
                Throw New ArgumentNullException("dependencyProp")
            End If
            If (activityStatusChangeListener Is Nothing) Then
                Throw New ArgumentNullException("activityStatusChangeListener")
            End If
            If ((((Not dependencyProp Is Activity.ExecutingEvent) AndAlso (Not dependencyProp Is Activity.CancelingEvent)) AndAlso ((Not dependencyProp Is Activity.ClosedEvent) AndAlso (Not dependencyProp Is Activity.CompensatingEvent))) AndAlso (((Not dependencyProp Is Activity.FaultingEvent) AndAlso (Not dependencyProp Is Activity.StatusChangedEvent)) AndAlso ((Not dependencyProp Is Activity.StatusChangedLockedEvent) AndAlso (Not dependencyProp Is Activity.LockCountOnStatusChangeChangedEvent)))) Then
                Throw New ArgumentException
            End If
            Dim list As IList = Nothing
            If MyBase.DependencyPropertyValues.ContainsKey(dependencyProp) Then
                list = [TryCast](MyBase.DependencyPropertyValues.Item(dependencyProp),IList)
            Else
                list = New ArrayList
                MyBase.DependencyPropertyValues.Item(dependencyProp) = list
            End If
            list.Add(New ActivityExecutorDelegateInfo([Of] ActivityExecutionStatusChangedEventArgs)(True, activityStatusChangeListener, Me.ContextActivity))
        End Sub

        Friend Sub ReleaseLockOnStatusChange(ByVal eventListener As IActivityEventListener([Of] ActivityExecutionStatusChangedEventArgs))
            Me.UnregisterForStatusChange(Activity.StatusChangedLockedEvent, eventListener)
            Dim lockCountOnStatusChange As Integer = Me.LockCountOnStatusChange
            MyBase.SetValue(Activity.LockCountOnStatusChangeProperty, --lockCountOnStatusChange)
            If (lockCountOnStatusChange = 0) Then
                If Not Me.HasPrimaryClosed Then
                    MyBase.SetValue(Activity.ExecutionResultProperty, ActivityExecutionResult.Canceled)
                End If
                Try 
                    Me.MarkClosed
                    Return
                Catch obj1 As Object
                    MyBase.SetValue(Activity.LockCountOnStatusChangeProperty, ++lockCountOnStatusChange)
                    Me.RegisterForStatusChange(Activity.StatusChangedLockedEvent, eventListener)
                    Throw
                End Try
            End If
            Me.FireStatusChangedEvents(Activity.LockCountOnStatusChangeChangedEvent, False)
        End Sub

        Private Sub RemoveStatusChangeHandler(ByVal dependencyProp As DependencyProperty, ByVal delegateValue As EventHandler([Of] ActivityExecutionStatusChangedEventArgs))
            If MyBase.DependencyPropertyValues.ContainsKey(dependencyProp) Then
                Dim list As IList = [TryCast](MyBase.DependencyPropertyValues.Item(dependencyProp),IList)
                If (Not list Is Nothing) Then
                    list.Remove(New ActivityExecutorDelegateInfo([Of] ActivityExecutionStatusChangedEventArgs)(True, delegateValue, Me.ContextActivity))
                    If (list.Count = 0) Then
                        MyBase.DependencyPropertyValues.Remove(dependencyProp)
                    End If
                End If
            End If
        End Sub

        Friend Sub ResetAllKnownDependencyProperties()
            Me.ResetKnownDependencyProperties(True)
        End Sub

        Private Sub ResetKnownDependencyProperties(ByVal forReexecute As Boolean)
            Dim array As DependencyProperty() = New DependencyProperty(MyBase.DependencyPropertyValues.Keys.Count  - 1) {}
            MyBase.DependencyPropertyValues.Keys.CopyTo(array, 0)
            Dim property As DependencyProperty
            For Each property In array
                If ([property].IsKnown AndAlso (([property].Validity = PropertyValidity.Uninitialize) OrElse (forReexecute AndAlso ([property].Validity = PropertyValidity.Reexecute)))) Then
                    MyBase.RemoveProperty([property])
                End If
            Next
        End Sub

        Private Function ResolveActivityByName(ByVal activityQualifiedName As String, ByVal withinThisActivityOnly As Boolean) As Activity
            Dim activity As Activity = Nothing
            If (Not MyBase.DesignMode AndAlso Not Me.DynamicUpdateMode) Then
                Dim rootActivity As Activity = Me.RootActivity
                Dim hashtable As Hashtable = DirectCast(rootActivity.UserData.Item(UserDataKeys.LookupPaths), Hashtable)
                If (Not hashtable Is Nothing) Then
                    Dim dottedPath As String = CStr(hashtable.Item(activityQualifiedName))
                    If (dottedPath Is Nothing) Then
                        Return activity
                    End If
                    If (dottedPath.Length <> 0) Then
                        Dim str2 As String = CStr(hashtable.Item(Me.QualifiedName))
                        If dottedPath.StartsWith(str2, StringComparison.Ordinal) Then
                            If (dottedPath.Length = str2.Length) Then
                                Return Me
                            End If
                            If ((str2.Length = 0) OrElse (dottedPath.Chars(str2.Length) = "."c)) Then
                                activity = Me.TraverseDottedPath(dottedPath.Substring(If((str2.Length > 0), (str2.Length + 1), 0)))
                            End If
                            Return activity
                        End If
                        If Not withinThisActivityOnly Then
                            activity = rootActivity.TraverseDottedPath(dottedPath)
                        End If
                        Return activity
                    End If
                    If Not withinThisActivityOnly Then
                        activity = rootActivity
                    End If
                End If
                Return activity
            End If
            If Not MyBase.DesignMode Then
                Dim compositeActivity As CompositeActivity = [TryCast](If(withinThisActivityOnly, DirectCast(Me, CompositeActivity), DirectCast(Me.RootActivity, CompositeActivity)),CompositeActivity)
                If (Not compositeActivity Is Nothing) Then
                    Dim activity4 As Activity
                    For Each activity4 In Helpers.GetNestedActivities(compositeActivity)
                        If (activity4.QualifiedName = activityQualifiedName) Then
                            Return activity4
                        End If
                    Next
                End If
                Return activity
            End If
            activity = Helpers.ParseActivity(Me, activityQualifiedName)
            If ((activity Is Nothing) AndAlso Not withinThisActivityOnly) Then
                activity = Helpers.ParseActivity(Me.RootActivity, activityQualifiedName)
            End If
            Return activity
        End Function

        Public Sub Save(ByVal stream As Stream)
            Me.Save(stream, Activity.binaryFormatter)
        End Sub

        Public Sub Save(ByVal stream As Stream, ByVal formatter As IFormatter)
            If (stream Is Nothing) Then
                Throw New ArgumentNullException("stream")
            End If
            If (formatter Is Nothing) Then
                Throw New ArgumentNullException("formatter")
            End If
            If MyBase.DesignMode Then
                Throw New InvalidOperationException(SR.GetString("Error_NoRuntimeAvailable"))
            End If
            Dim contextIdToActivityMap As Hashtable = Activity.ContextIdToActivityMap
            Activity.ContextIdToActivityMap = New Hashtable
            Try 
                Activity.FillContextIdToActivityMap(Me)
                Dim activity As Activity
                For Each activity In Activity.ContextIdToActivityMap.Values
                    Dim list As IList([Of] Activity) = activity.CollectNestedActivities
                    If ((Not list Is Nothing) AndAlso (list.Count > 0)) Then
                        activity.SetValue(Activity.NestedActivitiesProperty, list)
                    End If
                Next
                formatter.Serialize(stream, Me)
            Finally
                Dim activity2 As Activity
                For Each activity2 In Activity.ContextIdToActivityMap.Values
                    activity2.RemoveProperty(Activity.NestedActivitiesProperty)
                Next
                Activity.ContextIdToActivityMap = contextIdToActivityMap
                Activity.ActivityRoots = Nothing
            End Try
        End Sub

        Friend Sub SetParent(ByVal compositeActivity As CompositeActivity)
            Me.parent = compositeActivity
        End Sub

        Friend Sub SetStatus(ByVal newStatus As ActivityExecutionStatus, ByVal transacted As Boolean)
            WorkflowTrace.Runtime.TraceEvent(TraceEventType.Information, 0, "Activity Status Change - Activity: {0} Old:{1}; New:{2}", New Object() { Me.QualifiedName, Activity.ActivityExecutionStatusEnumToString(Me.ExecutionStatus), Activity.ActivityExecutionStatusEnumToString(newStatus) })
            If ((newStatus = ActivityExecutionStatus.Faulting) AndAlso (Me.ExecutionStatus = ActivityExecutionStatus.Executing)) Then
                MyBase.SetValue(Activity.WasExecutingProperty, True)
            End If
            MyBase.SetValue(Activity.ExecutionStatusProperty, newStatus)
            Me.FireStatusChangedEvents(Activity.StatusChangedEvent, transacted)
            Select Case newStatus
                Case ActivityExecutionStatus.Executing
                    Me.FireStatusChangedEvents(Activity.ExecutingEvent, transacted)
                    Exit Select
                Case ActivityExecutionStatus.Canceling
                    Me.FireStatusChangedEvents(Activity.CancelingEvent, transacted)
                    Exit Select
                Case ActivityExecutionStatus.Closed
                    Me.FireStatusChangedEvents(Activity.ClosedEvent, transacted)
                    Exit Select
                Case ActivityExecutionStatus.Compensating
                    Me.FireStatusChangedEvents(Activity.CompensatingEvent, transacted)
                    Exit Select
                Case ActivityExecutionStatus.Faulting
                    Me.FireStatusChangedEvents(Activity.FaultingEvent, transacted)
                    Exit Select
                Case Else
                    Return
            End Select
            Me.WorkflowCoreRuntime.ActivityStatusChanged(Me, transacted, False)
            If (newStatus = ActivityExecutionStatus.Closed) Then
                MyBase.RemoveProperty(Activity.LockCountOnStatusChangeProperty)
                MyBase.RemoveProperty(Activity.HasPrimaryClosedProperty)
                MyBase.RemoveProperty(Activity.WasExecutingProperty)
            End If
        End Sub

        Public Overrides Function ToString() As String
            Return (Me.QualifiedName & " [" & MyBase.GetType.FullName & "]")
        End Function

        Protected Sub TrackData(ByVal userData As Object)
            If (userData Is Nothing) Then
                Throw New ArgumentNullException("userData")
            End If
            If (Me.WorkflowCoreRuntime Is Nothing) Then
                Throw New InvalidOperationException(SR.GetString("Error_NoRuntimeAvailable"))
            End If
            Me.WorkflowCoreRuntime.Track(Nothing, userData)
        End Sub

        Protected Sub TrackData(ByVal userDataKey As String, ByVal userData As Object)
            If (userData Is Nothing) Then
                Throw New ArgumentNullException("userData")
            End If
            If (Me.WorkflowCoreRuntime Is Nothing) Then
                Throw New InvalidOperationException(SR.GetString("Error_NoRuntimeAvailable"))
            End If
            Me.WorkflowCoreRuntime.Track(userDataKey, userData)
        End Sub

        Friend Overridable Function TraverseDottedPath(ByVal dottedPath As String) As Activity
            Return Nothing
        End Function

        Friend Function TraverseDottedPathFromRoot(ByVal dottedPathFromRoot As String) As Activity
            Dim dottedPath As String = Me.DottedPath
            If (dottedPathFromRoot = dottedPath) Then
                Return Me
            End If
            If Not dottedPathFromRoot.StartsWith(dottedPath, StringComparison.Ordinal) Then
                Return Nothing
            End If
            Dim str2 As String = dottedPathFromRoot
            If (dottedPath.Length > 0) Then
                str2 = dottedPathFromRoot.Substring((dottedPath.Length + 1))
            End If
            Return Me.TraverseDottedPath(str2)
        End Function

        Protected Friend Overridable Sub Uninitialize(ByVal provider As IServiceProvider)
            If (provider Is Nothing) Then
                Throw New ArgumentNullException("provider")
            End If
            Me.ResetKnownDependencyProperties(False)
        End Sub

        Private Shared Sub UninitializeCompletedContext(ByVal activity As Activity, ByVal executionContext As ActivityExecutionContext)
            Dim collection As IList([Of] ActivityExecutionContextInfo) = [TryCast](activity.GetValue(Activity.CompletedExecutionContextsProperty),IList([Of] ActivityExecutionContextInfo))
            If ((Not collection Is Nothing) AndAlso (collection.Count > 0)) Then
                Dim list2 As IList([Of] ActivityExecutionContextInfo) = New List([Of] ActivityExecutionContextInfo)(collection)
                Dim info As ActivityExecutionContextInfo
                For Each info In list2
                    If ((CByte((info.Flags And PersistFlags.NeedsCompensation)) <> 0) AndAlso (Not activity.GetActivityByName(info.ActivityQualifiedName, True) Is Nothing)) Then
                        Dim context As ActivityExecutionContext = executionContext.ExecutionContextManager.DiscardPersistedExecutionContext(info)
                        Activity.UninitializeCompletedContext(context.Activity, context)
                        executionContext.ExecutionContextManager.CompleteExecutionContext(context)
                    End If
                Next
            End If
            Dim compositeActivity As CompositeActivity = [TryCast](activity,CompositeActivity)
            If (Not compositeActivity Is Nothing) Then
                Dim compensatableChildren As Activity() = CompensationUtils.GetCompensatableChildren(compositeActivity)
                Dim i As Integer = (compensatableChildren.Length - 1)
                Do While (i >= 0)
                    Dim activity3 As Activity = DirectCast(compensatableChildren.GetValue(i), Activity)
                    activity3.Uninitialize(activity.RootActivity.WorkflowCoreRuntime)
                    activity3.SetValue(Activity.ExecutionResultProperty, ActivityExecutionResult.Uninitialized)
                    i -= 1
                Loop
            End If
            activity.Uninitialize(activity.RootActivity.WorkflowCoreRuntime)
            activity.SetValue(Activity.ExecutionResultProperty, ActivityExecutionResult.Uninitialized)
        End Sub

        Public Sub UnregisterForStatusChange(ByVal dependencyProp As DependencyProperty, ByVal activityStatusChangeListener As IActivityEventListener([Of] ActivityExecutionStatusChangedEventArgs))
            If (dependencyProp Is Nothing) Then
                Throw New ArgumentNullException("dependencyProp")
            End If
            If (activityStatusChangeListener Is Nothing) Then
                Throw New ArgumentNullException("activityStatusChangeListener")
            End If
            If ((((Not dependencyProp Is Activity.ExecutingEvent) AndAlso (Not dependencyProp Is Activity.CancelingEvent)) AndAlso ((Not dependencyProp Is Activity.ClosedEvent) AndAlso (Not dependencyProp Is Activity.CompensatingEvent))) AndAlso (((Not dependencyProp Is Activity.FaultingEvent) AndAlso (Not dependencyProp Is Activity.StatusChangedEvent)) AndAlso ((Not dependencyProp Is Activity.StatusChangedLockedEvent) AndAlso (Not dependencyProp Is Activity.LockCountOnStatusChangeChangedEvent)))) Then
                Throw New ArgumentException
            End If
            If MyBase.DependencyPropertyValues.ContainsKey(dependencyProp) Then
                Dim list As IList = [TryCast](MyBase.DependencyPropertyValues.Item(dependencyProp),IList)
                If (Not list Is Nothing) Then
                    list.Remove(New ActivityExecutorDelegateInfo([Of] ActivityExecutionStatusChangedEventArgs)(True, activityStatusChangeListener, Me.ContextActivity))
                    If (list.Count = 0) Then
                        MyBase.DependencyPropertyValues.Remove(dependencyProp)
                    End If
                End If
            End If
        End Sub


        ' Properties
        Friend ReadOnly Property CachedDottedPath As String
            Get
                Return Me.cachedDottedPath
            End Get
        End Property

        Friend ReadOnly Property CanUninitializeNow As Boolean
            Get
                If Me.NeedsCompensation Then
                    Return False
                End If
                Dim contextActivity As Activity = Me.ContextActivity
                If (Not contextActivity Is Me) Then
                    Dim list As IList([Of] ActivityExecutionContextInfo) = [TryCast](contextActivity.GetValue(Activity.CompletedExecutionContextsProperty),IList([Of] ActivityExecutionContextInfo))
                    If ((Not list Is Nothing) AndAlso (list.Count > 0)) Then
                        Dim info As ActivityExecutionContextInfo
                        For Each info In list
                            If ((CByte((info.Flags And PersistFlags.NeedsCompensation)) <> 0) AndAlso (Not Me.GetActivityByName(info.ActivityQualifiedName, True) Is Nothing)) Then
                                Return False
                            End If
                        Next
                    End If
                End If
                Return True
            End Get
        End Property

        Friend ReadOnly Property ContextActivity As Activity
            Get
                Dim parent As Activity = Me
                Do While ((Not parent Is Nothing) AndAlso (parent.GetValue(Activity.ActivityExecutionContextInfoProperty) Is Nothing))
                    parent = parent.parent
                Loop
                Return parent
            End Get
        End Property

        Friend ReadOnly Property ContextGuid As Guid
            Get
                Return DirectCast(Me.ContextActivity.GetValue(Activity.ActivityExecutionContextInfoProperty), ActivityExecutionContextInfo).ContextGuid
            End Get
        End Property

        Friend ReadOnly Property ContextId As Integer
            Get
                Return DirectCast(Me.ContextActivity.GetValue(Activity.ActivityExecutionContextInfoProperty), ActivityExecutionContextInfo).ContextId
            End Get
        End Property

        <SRDescription("DescriptionDescr"), Browsable(True), Editor(GetType(MultilineStringEditor), GetType(UITypeEditor)), DefaultValue(""), SRCategory("Activity")> _
        Public Property Description As String
            Get
                Return CStr(MyBase.GetValue(Activity.DescriptionProperty))
            End Get
            Set(ByVal value As String)
                MyBase.SetValue(Activity.DescriptionProperty, value)
            End Set
        End Property

        Friend ReadOnly Property DottedPath As String
            Get
                If (Not MyBase.DesignMode AndAlso Not Me.DynamicUpdateMode) Then
                    Dim str As String = CStr(MyBase.GetValue(Activity.DottedPathProperty))
                    If (Not str Is Nothing) Then
                        Return str
                    End If
                End If
                Dim builder As New StringBuilder
                Dim activity As Activity = Me
                Do While (Not activity.parent Is Nothing)
                    builder.Insert(0, activity.parent.Activities.IndexOf(activity).ToString(CultureInfo.InvariantCulture))
                    builder.Insert(0, "."c)
                    activity = activity.parent
                Loop
                If (builder.Length > 0) Then
                    builder.Remove(0, 1)
                End If
                Return builder.ToString
            End Get
        End Property

        Friend Property DynamicUpdateMode As Boolean
            Get
                Return (Not Me.cachedDottedPath Is Nothing)
            End Get
            Set(ByVal value As Boolean)
                If value Then
                    Me.cachedDottedPath = Me.DottedPath
                Else
                    Me.cachedDottedPath = Nothing
                End If
            End Set
        End Property

        <SRDescription("EnabledDescr"), DefaultValue(True), SRCategory("Activity"), Browsable(True)> _
        Public Property Enabled As Boolean
            Get
                Return CBool(MyBase.GetValue(Activity.EnabledProperty))
            End Get
            Set(ByVal value As Boolean)
                MyBase.SetValue(Activity.EnabledProperty, value)
            End Set
        End Property

        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Public ReadOnly Property ExecutionResult As ActivityExecutionResult
            Get
                Return DirectCast(MyBase.GetValue(Activity.ExecutionResultProperty), ActivityExecutionResult)
            End Get
        End Property

        <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(False)> _
        Public ReadOnly Property ExecutionStatus As ActivityExecutionStatus
            Get
                Return DirectCast(MyBase.GetValue(Activity.ExecutionStatusProperty), ActivityExecutionStatus)
            End Get
        End Property

        <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(False)> _
        Friend ReadOnly Property HasPrimaryClosed As Boolean
            Get
                Return CBool(MyBase.GetValue(Activity.HasPrimaryClosedProperty))
            End Get
        End Property

        Friend ReadOnly Property IsContextActivity As Boolean
            Get
                Return (Not MyBase.GetValue(Activity.ActivityExecutionContextInfoProperty) Is Nothing)
            End Get
        End Property

        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Public ReadOnly Property IsDynamicActivity As Boolean
            Get
                If MyBase.DesignMode Then
                    Return False
                End If
                Return (Not Me.ContextActivity Is Me.RootActivity)
            End Get
        End Property

        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Friend ReadOnly Property LockCountOnStatusChange As Integer
            Get
                Return CInt(MyBase.GetValue(Activity.LockCountOnStatusChangeProperty))
            End Get
        End Property

        <DefaultValue(""), Browsable(True), SRCategory("Activity"), ParenthesizePropertyName(True), SRDescription("NameDescr"), MergableProperty(False)> _
        Public Property Name As String
            Get
                Return CStr(MyBase.GetValue(Activity.NameProperty))
            End Get
            Set(ByVal value As String)
                MyBase.SetValue(Activity.NameProperty, value)
            End Set
        End Property

        Friend ReadOnly Property NeedsCompensation As Boolean
            Get
                Dim list As IList([Of] ActivityExecutionContextInfo) = [TryCast](MyBase.GetValue(Activity.CompletedExecutionContextsProperty),IList([Of] ActivityExecutionContextInfo))
                If ((Not list Is Nothing) AndAlso (list.Count > 0)) Then
                    Dim info As ActivityExecutionContextInfo
                    For Each info In list
                        If ((CByte((info.Flags And PersistFlags.NeedsCompensation)) <> 0) AndAlso (Not Me.GetActivityByName(info.ActivityQualifiedName, True) Is Nothing)) Then
                            Return True
                        End If
                    Next
                End If
                Dim queue As New Queue([Of] Activity)
                queue.Enqueue(Me)
                Do While (queue.Count > 0)
                    Dim activity As Activity = queue.Dequeue
                    If ((TypeOf activity Is ICompensatableActivity AndAlso (activity.ExecutionStatus = ActivityExecutionStatus.Closed)) AndAlso (activity.ExecutionResult = ActivityExecutionResult.Succeeded)) Then
                        Return True
                    End If
                    If TypeOf activity Is CompositeActivity Then
                        Dim activity2 As Activity
                        For Each activity2 In DirectCast(activity, CompositeActivity).Activities
                            If activity2.Enabled Then
                                queue.Enqueue(activity2)
                            End If
                        Next
                    End If
                Loop
                Return False
            End Get
        End Property

        <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(False)> _
        Public ReadOnly Property Parent As CompositeActivity
            Get
                Return Me.parent
            End Get
        End Property

        Friend ReadOnly Property ParentContextActivity As Activity
            Get
                Dim info As ActivityExecutionContextInfo = DirectCast(Me.ContextActivity.GetValue(Activity.ActivityExecutionContextInfoProperty), ActivityExecutionContextInfo)
                If (info.ParentContextId = -1) Then
                    Return Nothing
                End If
                Return Me.WorkflowCoreRuntime.GetContextActivityForId(info.ParentContextId)
            End Get
        End Property

        Friend ReadOnly Property PersistOnClose As Boolean
            Get
                If MyBase.UserData.Contains(GetType(PersistOnCloseAttribute)) Then
                    Return CBool(MyBase.UserData.Item(GetType(PersistOnCloseAttribute)))
                End If
                Dim customAttributes As Object() = MyBase.GetType.GetCustomAttributes(GetType(PersistOnCloseAttribute), True)
                Return ((Not customAttributes Is Nothing) AndAlso (customAttributes.Length > 0))
            End Get
        End Property

        <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(False)> _
        Public ReadOnly Property QualifiedName As String
            Get
                If (Not MyBase.DesignMode AndAlso Not Me.DynamicUpdateMode) Then
                    Dim str As String = CStr(MyBase.GetValue(Activity.QualifiedNameProperty))
                    If (Not str Is Nothing) Then
                        Return str
                    End If
                End If
                If Helpers.IsActivityLocked(Me) Then
                    Return InternalHelpers.GenerateQualifiedNameForLockedActivity(Me, Nothing)
                End If
                Return CStr(MyBase.GetValue(Activity.NameProperty))
            End Get
        End Property

        Friend ReadOnly Property RootActivity As Activity
            Get
                Dim parent As Activity = Me
                Do While (Not parent.parent Is Nothing)
                    parent = parent.parent
                Loop
                Return parent
            End Get
        End Property

        Friend ReadOnly Property RootContextActivity As Activity
            Get
                Return Me.WorkflowCoreRuntime.RootActivity
            End Get
        End Property

        Friend ReadOnly Property SupportsSynchronization As Boolean
            Get
                Return TypeOf Me Is SynchronizationScopeActivity
            End Get
        End Property

        Friend ReadOnly Property SupportsTransaction As Boolean
            Get
                Return (TypeOf Me Is CompensatableTransactionScopeActivity OrElse TypeOf Me Is TransactionScopeActivity)
            End Get
        End Property

        <Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
        Friend ReadOnly Property WasExecuting As Boolean
            Get
                Return CBool(MyBase.GetValue(Activity.WasExecutingProperty))
            End Get
        End Property

        <DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(False)> _
        Friend ReadOnly Property WorkflowCoreRuntime As IWorkflowCoreRuntime
            Get
                Return Me.workflowCoreRuntime
            End Get
        End Property

        Protected ReadOnly Property WorkflowInstanceId As Guid
            Get
                If (Me.WorkflowCoreRuntime Is Nothing) Then
                    Throw New InvalidOperationException(SR.GetString("Error_NoRuntimeAvailable"))
                End If
                Return Me.WorkflowCoreRuntime.InstanceID
            End Get
        End Property


        ' Fields
        Friend Shared ReadOnly ActiveExecutionContextsProperty As DependencyProperty = DependencyProperty.RegisterAttached("ActiveExecutionContexts", GetType(IList), GetType(Activity))
        Public Shared ReadOnly ActivityContextGuidProperty As DependencyProperty = DependencyProperty.RegisterAttached("ActivityContextGuid", GetType(Guid), GetType(Activity), New PropertyMetadata(Guid.Empty))
        Private Shared activityDefinitionResolve As ActivityResolveEventHandler = Nothing
        Friend Shared ReadOnly ActivityExecutionContextInfoProperty As DependencyProperty = DependencyProperty.RegisterAttached("ActivityExecutionContextInfo", GetType(ActivityExecutionContextInfo), GetType(Activity))
        <ThreadStatic> _
        Friend Shared ActivityRoots As ArrayList = Nothing
        Friend Shared ActivityType As Type = Nothing
        Private Shared ReadOnly binaryFormatter As BinaryFormatter = Nothing
        <NonSerialized> _
        Private cachedDottedPath As String
        Public Shared ReadOnly CancelingEvent As DependencyProperty = DependencyProperty.Register("Canceling", GetType(EventHandler([Of] ActivityExecutionStatusChangedEventArgs)), GetType(Activity))
        Public Shared ReadOnly ClosedEvent As DependencyProperty = DependencyProperty.Register("Closed", GetType(EventHandler([Of] ActivityExecutionStatusChangedEventArgs)), GetType(Activity))
        Public Shared ReadOnly CompensatingEvent As DependencyProperty = DependencyProperty.Register("Compensating", GetType(EventHandler([Of] ActivityExecutionStatusChangedEventArgs)), GetType(Activity))
        Friend Shared ReadOnly CompletedExecutionContextsProperty As DependencyProperty = DependencyProperty.RegisterAttached("CompletedExecutionContexts", GetType(IList), GetType(Activity))
        Friend Shared ReadOnly CompletedOrderIdProperty As DependencyProperty = DependencyProperty.Register("CompletedOrderId", GetType(Integer), GetType(Activity), New PropertyMetadata(0))
        <ThreadStatic> _
        Friend Shared ContextIdToActivityMap As Hashtable = Nothing
        Friend Shared ReadOnly CustomActivityProperty As DependencyProperty = DependencyProperty.Register("CustomActivity", GetType(Boolean), GetType(Activity), New PropertyMetadata(DependencyPropertyOptions.Metadata))
        <ThreadStatic> _
        Friend Shared DefinitionActivity As Activity = Nothing
        Private Shared DescriptionProperty As DependencyProperty = DependencyProperty.Register("Description", GetType(String), GetType(Activity), New PropertyMetadata("", DependencyPropertyOptions.Metadata))
        Private Shared DottedPathProperty As DependencyProperty = DependencyProperty.Register("DottedPath", GetType(String), GetType(Activity), New PropertyMetadata((DependencyPropertyOptions.Metadata Or DependencyPropertyOptions.ReadOnly)))
        Private Shared EnabledProperty As DependencyProperty = DependencyProperty.Register("Enabled", GetType(Boolean), GetType(Activity), New PropertyMetadata(True, DependencyPropertyOptions.Metadata))
        Public Shared ReadOnly ExecutingEvent As DependencyProperty = DependencyProperty.Register("Executing", GetType(EventHandler([Of] ActivityExecutionStatusChangedEventArgs)), GetType(Activity))
        Friend Shared ReadOnly ExecutionResultProperty As DependencyProperty = DependencyProperty.RegisterAttached("ExecutionResult", GetType(ActivityExecutionResult), GetType(Activity), New PropertyMetadata(ActivityExecutionResult.None, New Attribute() { New BrowsableAttribute(False), New DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden) }))
        Friend Shared ReadOnly ExecutionStatusProperty As DependencyProperty = DependencyProperty.RegisterAttached("ExecutionStatus", GetType(ActivityExecutionStatus), GetType(Activity), New PropertyMetadata(ActivityExecutionStatus.Initialized, New Attribute() { New BrowsableAttribute(False), New DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden) }))
        Public Shared ReadOnly FaultingEvent As DependencyProperty = DependencyProperty.Register("Faulting", GetType(EventHandler([Of] ActivityExecutionStatusChangedEventArgs)), GetType(Activity))
        Friend Shared ReadOnly HasPrimaryClosedProperty As DependencyProperty = DependencyProperty.RegisterAttached("HasPrimaryClosed", GetType(Boolean), GetType(Activity), New PropertyMetadata(False))
        Friend Shared ReadOnly LockCountOnStatusChangeChangedEvent As DependencyProperty = DependencyProperty.Register("LockCountOnStatusChangeChanged", GetType(EventHandler([Of] ActivityExecutionStatusChangedEventArgs)), GetType(Activity))
        Private Shared ReadOnly LockCountOnStatusChangeProperty As DependencyProperty = DependencyProperty.RegisterAttached("LockCountOnStatusChange", GetType(Integer), GetType(Activity), New PropertyMetadata(0))
        Private Shared NameProperty As DependencyProperty = DependencyProperty.Register("Name", GetType(String), GetType(Activity), New PropertyMetadata("", DependencyPropertyOptions.Metadata, New Attribute() { New ValidationOptionAttribute(ValidationOption.Required) }))
        Private Shared ReadOnly NestedActivitiesProperty As DependencyProperty = DependencyProperty.RegisterAttached("NestedActivities", GetType(IList([Of] Activity)), GetType(Activity))
        <NonSerialized> _
        Friend parent As CompositeActivity
        Private Shared QualifiedNameProperty As DependencyProperty = DependencyProperty.Register("QualifiedName", GetType(String), GetType(Activity), New PropertyMetadata((DependencyPropertyOptions.Metadata Or DependencyPropertyOptions.ReadOnly)))
        Private Shared ReadOnly SerializedStreamLengthProperty As DependencyProperty = DependencyProperty.RegisterAttached("SerializedStreamLength", GetType(Long), GetType(Activity), New PropertyMetadata(DependencyPropertyOptions.NonSerialized))
        Private Shared staticSyncRoot As Object = New Object
        Public Shared ReadOnly StatusChangedEvent As DependencyProperty = DependencyProperty.Register("StatusChanged", GetType(EventHandler([Of] ActivityExecutionStatusChangedEventArgs)), GetType(Activity))
        Friend Shared ReadOnly StatusChangedLockedEvent As DependencyProperty = DependencyProperty.Register("StatusChangedLocked", GetType(EventHandler([Of] ActivityExecutionStatusChangedEventArgs)), GetType(Activity))
        Friend Shared ReadOnly SynchronizationHandlesProperty As DependencyProperty = DependencyProperty.Register("SynchronizationHandles", GetType(ICollection([Of] String)), GetType(Activity), New PropertyMetadata(DependencyPropertyOptions.Metadata))
        Friend Shared ReadOnly WasExecutingProperty As DependencyProperty = DependencyProperty.RegisterAttached("WasExecuting", GetType(Boolean), GetType(Activity), New PropertyMetadata(False, New Attribute() { New BrowsableAttribute(False), New DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden) }))
        Private Shared workflowChangeActionsResolve As WorkflowChangeActionsResolveEventHandler = Nothing
        <NonSerialized> _
        Private workflowCoreRuntime As IWorkflowCoreRuntime
        Friend Shared ReadOnly WorkflowDefinitionProperty As DependencyProperty = DependencyProperty.RegisterAttached("WorkflowDefinition", GetType(Activity), GetType(Activity), New PropertyMetadata(DependencyPropertyOptions.NonSerialized))
        Friend Shared ReadOnly WorkflowRulesMarkupProperty As DependencyProperty = DependencyProperty.Register("WorkflowRulesMarkup", GetType(String), GetType(Activity))
        Friend Shared ReadOnly WorkflowRuntimeProperty As DependencyProperty = DependencyProperty.RegisterAttached("WorkflowRuntime", GetType(IServiceProvider), GetType(Activity), New PropertyMetadata(DependencyPropertyOptions.NonSerialized))
        Friend Shared ReadOnly WorkflowXamlMarkupProperty As DependencyProperty = DependencyProperty.Register("WorkflowXamlMarkup", GetType(String), GetType(Activity))
    End Class
End Namespace

